# Definition for singly-linked list.
class ListNode:
    def __init__(self, x):
        self.val = x
        self.next = None


class Solution:
    def removeElements(self, head: ListNode, val: int) -> ListNode:
        head, head.next = ListNode(None), head
        now_note = head
        # now_note = ListNode(None)
        # now_note.next, head = head, now_note
        while now_note and now_note.next:
            if now_note.next.val == val:
                now_note.next = now_note.next.next
            else:
                now_note = now_note.next
        return head.next
